package idv.takeshi.software.productline.bookstore.domain.model.useraccount;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * A model class which representing a individual user account.
 * @author takeshi
 *
 */
@Entity
@Table(name = "INDIVIDUAL_ACCOUNT")
public class IndividualAccount extends UserAccount {
	
	@Column(name = "LAST_NAME", nullable = false, length = 20)
	private String lastName;
	
	@Column(name = "FIRST_NAME", nullable = false, length = 20) 
	private String firstName;
	
	@Column(nullable = false, length = 50)
	@Enumerated(EnumType.STRING)
	private Sex sex;
	 
	@Column(name = "BIRTHDAY", nullable = false)
	private Date birthday;

	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return the sex
	 */
	public Sex getSex() {
		return sex;
	}

	/**
	 * @param sex the sex to set
	 */
	public void setSex(Sex sex) {
		this.sex = sex;
	}

	/**
	 * @return the birthday
	 */
	public Date getBirthday() {
		return birthday;
	}

	/**
	 * @param birthday the birthday to set
	 */
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Override
	public String getUserName() {
		return this.lastName + " " + this.firstName;
	}

	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.model.useraccount.UserAccount#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		   if (obj == this) { return true; }
		   if (obj.getClass() != getClass()) {
		     return false;
		   }
		   IndividualAccount rhs = (IndividualAccount) obj;
		   return new EqualsBuilder()
		   	   .appendSuper(super.equals(rhs))
			   .append(this.lastName, rhs.lastName)
			   .append(this.firstName, rhs.firstName)
			   .append(this.sex, rhs.sex)
			   .append(this.birthday, rhs.birthday)
		       .isEquals();
	}

	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.model.useraccount.UserAccount#hashCode()
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder(11, 13).
		   appendSuper(super.hashCode()).
	       append(this.lastName).
	       append(this.firstName).
	       append(this.sex).
	       append(this.birthday).
	       toHashCode();
	}
	 
}
 
